package com.imooc.springbootdemo.controller;

import com.imooc.springbootdemo.entity.Area;
import com.imooc.springbootdemo.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jiangfeixiang on 2018/4/8
 */
@RestController
@RequestMapping("/area")
public class AreaController {
    //注入AreaService
    @Autowired
    private AreaService areaService;

    /**
     * 查询所有区域信息
     * @return
     */
    @RequestMapping(value = "/getArea",method = RequestMethod.GET)
    public Map<String,Object> getArea(){
        Map<String,Object> modelMap = new HashMap<>();
       List<Area> list = areaService.queryArea();
        modelMap.put("list",list);
        return modelMap;
    }
    /**
     * 根据id查询
     */
    @RequestMapping(value = "/getAreaById",method = RequestMethod.GET)
    public Map<String,Object> getAreaById(Integer areaId){
        Map<String,Object> modelMap = new HashMap<>();
        Area area = areaService.queryAreaById(areaId);
        modelMap.put("area",area);
        return modelMap;
    }
    /**
     * 添加区域信息
     */
    @RequestMapping(value = "/insertArea",method = RequestMethod.POST)
    public Map<String,Object> insertArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.insertArea(area));
        return modelMap;
    }

    /**
     * 修改区域信息
     */
    @RequestMapping(value = "/updateArea",method = RequestMethod.POST)
    public Map<String,Object> updateArea(@RequestBody Area area){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.updateArea(area));
        return modelMap;
    }
    /**
     * 删除区域信息
     */
    @RequestMapping(value = "/deleteArea",method = RequestMethod.GET)
    public Map<String,Object> deleteArea(Integer areaId){
        Map<String,Object> modelMap = new HashMap<>();
        modelMap.put("success",areaService.deleteArea(areaId));
        return modelMap;
    }
}
